var $content;

function triggerLoginForm(){
	$("#btLogin").click(function(e){
		e.preventDefault();

		$.mobile.showPageLoadingMsg();

		var pseudo = $('input[name*="pseudo"]').val();
		var mdp = $('input[name*="mdp"]').val();

		logUser(pseudo, mdp);

	})
}

function logUser(pseudo, mdp){
	var dataUser = 
		{
		   "username":pseudo,	
		   "password":mdp
		};

	$.ajax ({
		data: dataUser,
		type: 'post',
		dataType: "json",
		url : "http://vlove.helia-agency.com/vloveur/user/login.json",
		success: function(result){
			console.log(result);

			localStorage.setItem("uid", result.user.uid);

			$.mobile.changePage( "map.html" );

			$.mobile.hidePageLoadingMsg();

		},
		error : function (XMLHttpRequest, textStatus, errorThrown){
			$('p.error').html(errorThrown).show();

			$.mobile.hidePageLoadingMsg();
		}
	});
}

$("#login").on("pageshow", function (event) {
	$('.menu').load('menu.html',function(){ $('#menu').panel(); });

	triggerLoginForm();
});